Skip to content

feat(mcp): Add opt-in idle timeout shutdown#398

Merged
cameroncooke merged 5 commits intomainfrom
issue_394
May 7, 2026
Merged

feat(mcp): Add opt-in idle timeout shutdown#398
cameroncooke merged 5 commits intomainfrom
issue_394

Conversation

@cameroncooke
Copy link
Copy Markdown
Collaborator

Add an opt-in MCP server idle shutdown path controlled by XCODEBUILDMCP_MCP_IDLE_TIMEOUT_MS.

MCP mode previously stayed alive until the client disconnected or the process was otherwise terminated. This adds a default-disabled idle timeout that exits through the existing graceful lifecycle shutdown path once the configured idle period has elapsed, no MCP request is in flight, and no registered runtime operation is active.

The implementation tracks JSON-RPC request lifecycles at the stdio transport boundary so regular MCP requests, not just tool handlers, keep the server alive. It also adds unit coverage for parsing, timer behavior, lifecycle request tracking, and a process-level MCP e2e test that starts the built CLI and asserts the server exits cleanly after the configured timeout.

Fixes #394

Add an MCP server idle timeout controlled by XCODEBUILDMCP_MCP_IDLE_TIMEOUT_MS.
The timeout is disabled by default and only shuts down after the server is idle,
there are no in-flight MCP requests, and no registered runtime operations remain.

Track JSON-RPC request lifecycles at the stdio transport boundary so the idle
controller observes normal MCP requests without changing individual tool handlers.
Add unit coverage and a process-level MCP e2e test that proves the real server
exits gracefully after the configured idle timeout.

Fixes #394
Co-Authored-By: Codex <noreply@openai.com>
@cameroncooke cameroncooke marked this pull request as ready for review May 6, 2026 21:37
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 6, 2026

Open in StackBlitz

npm i https://pkg.pr.new/xcodebuildmcp@398

commit: 6bcf502

Comment thread src/server/request-lifecycle.ts
Comment thread src/server/request-lifecycle.ts
Comment thread src/server/request-lifecycle.ts
cameroncooke and others added 3 commits May 6, 2026 22:40
Avoid inflating the MCP idle in-flight counter when a client reuses a pending
JSON-RPC request id. Also clear the pending request if downstream message
handling throws synchronously before a response can be sent.

Refs #394
Co-Authored-By: Codex <noreply@openai.com>
Move the real MCP process idle-timeout test out of snapshot tests because it
asserts behavior directly and does not use snapshot fixtures.

Refs #394
Co-Authored-By: Codex <noreply@openai.com>
Assert the real MCP server process remains running when no idle timeout is
configured, then separately assert the opt-in timeout exits gracefully.

Refs #394
Co-Authored-By: Codex <noreply@openai.com>
@cameroncooke cameroncooke merged commit 2fd6069 into main May 7, 2026
39 checks passed
@cameroncooke cameroncooke deleted the issue_394 branch May 7, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP server mode lacks idle timeout (daemon mode has it)

1 participant